#include "UnityCG.cginc"
#include "../PBR/Common.hlsl"

sampler2D MapDepth;
sampler2D MapWPos;
sampler2D MapWNom;
sampler2D MapFlux;

uniform float4x4 MatLight;
uniform float4x4 MatLightProj;

struct VS_IN {
	float4 vertex : POSITION;
	float3 normal : NORMAL;
};

struct FS_IN {
	float4 vertex : SV_POSITION;
	float4 lvPos : TEXCOORD0;
	float3 lvNom : TEXCOORD1;
	float4 lcPos : TEXCOORD2;
};

#define VS_OUT FS_IN

VS_OUT vert(VS_IN i) {
	float4x4 MatLightMV = mul(MatLight, UNITY_MATRIX_M);
	float4x4 MatLightITMV = MatLightMV;
	VS_OUT o = (VS_OUT)0;
	o.vertex = UnityObjectToClipPos(i.vertex);
	o.lvPos = mul(MatLightMV, i.vertex);
	o.lcPos = mul(MatLightProj, o.lvPos);
	o.lvNom = mul(MatLightITMV, float4(i.normal, 0)).xyz;
	return o;
}

float4 frag(FS_IN i) : SV_Target {
	float lDepth = i.lcPos.z / i.lcPos.w;
	float2 lUV = i.lcPos.xy * 0.5 + 0.5;
	float depth = tex2D(MapDepth, lUV).r;
	return float4(i.lvPos);
}